﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class LoaiBoKichDienDAO
    {
        // LOADLOAIKICHDIEN
        public DataTable LoadLoaiKD()
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlDataAdapter _da = new SqlDataAdapter("LOADLOAIKICHDIEN", _cn);
            _da.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;

            DataTable _dt = new DataTable();
            _da.Fill(_dt);
            return _dt;
        }

        //THEMLOAIKICHDIEN
        public void ThemLoaiKD(LoaiBoKichDienDTO lkdDTO)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlCommand cmd = new SqlCommand("THEMLOAIKICHDIEN", _cn);
            cmd.CommandType = CommandType.StoredProcedure;


            //cmd.Parameters.Add(new SqlParameter("@MaLoai", SqlDbType.Int));
            cmd.Parameters.Add(new SqlParameter("@TenLoai", SqlDbType.NVarChar, 50));

            //cmd.Parameters["@MaTB"].Value = lkdDTO.MALOAIKD;
            cmd.Parameters["@TenLoai"].Value = lkdDTO.TENLOAIKD;

            //int _kq = cmd.ExecuteNonQuery();
            cmd.ExecuteNonQuery();
            _cn.Close();
            // return _kq;
        }

        //SUALOAIKICHDIEN
        public int SuaLoaiKD(LoaiBoKichDienDTO lkdDTO)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlCommand cmd = new SqlCommand("SUALOAIKICHDIEN", _cn);
            cmd.CommandType = CommandType.StoredProcedure;


            cmd.Parameters.Add(new SqlParameter("@MaLoai", SqlDbType.Int));
            cmd.Parameters.Add(new SqlParameter("@TenLoai", SqlDbType.NVarChar, 50));

            cmd.Parameters["@MaLoai"].Value = lkdDTO.MALOAIKD;
            cmd.Parameters["@TenLoai"].Value = lkdDTO.TENLOAIKD;

            int _kq = cmd.ExecuteNonQuery();
            _cn.Close();
            return _kq;
        }

        //XOALOAIKICHDIEN
        public int XoaLoaiKD(LoaiBoKichDienDTO lkdDTO)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlCommand cmd = new SqlCommand("XOALOAIKICHDIEN", _cn);
            cmd.CommandType = CommandType.StoredProcedure;


            cmd.Parameters.Add(new SqlParameter("@MaLoai", SqlDbType.Int));
            //cmd.Parameters.Add(new SqlParameter("@TenLoai", SqlDbType.NVarChar, 50));

            cmd.Parameters["@MaLoai"].Value = lkdDTO.MALOAIKD;
            //cmd.Parameters["@TenLoai"].Value = lkdDTO.TENLOAIKD;

            int _kq = cmd.ExecuteNonQuery();
            _cn.Close();
            return _kq;
        }

        //KIEMTRALOAIKICHDIEN
        public int KTLoaiKD(LoaiBoKichDienDTO lkdDTO)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlCommand cmd = new SqlCommand("KTLOAIKICHDIEN", _cn);
            cmd.CommandType = CommandType.StoredProcedure;


            //cmd.Parameters.Add(new SqlParameter("@MaLoai", SqlDbType.Int));
            cmd.Parameters.Add(new SqlParameter("@TenLoai", SqlDbType.NVarChar, 50));
            cmd.Parameters.Add(new SqlParameter("@out", SqlDbType.Int));
            cmd.Parameters["@out"].Direction = ParameterDirection.Output;

            //cmd.Parameters["@MaLoai"].Value = lkdDTO.MALOAIKD;
            cmd.Parameters["@TenLoai"].Value = lkdDTO.TENLOAIKD;

            cmd.ExecuteNonQuery();
            int _kq = (int)cmd.Parameters["@out"].Value;
            _cn.Close();
            return _kq;
        }

        //KIEMTRAMALOAIKICHDIEN
        public int KTMaLoaiKD(LoaiBoKichDienDTO lkdDTO)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlCommand cmd = new SqlCommand("KTMALOAIKICHDIEN", _cn);
            cmd.CommandType = CommandType.StoredProcedure;


            cmd.Parameters.Add(new SqlParameter("@MaLoai", SqlDbType.Int));
            //cmd.Parameters.Add(new SqlParameter("@TenLoai", SqlDbType.NVarChar, 50));
            cmd.Parameters.Add(new SqlParameter("@out", SqlDbType.Int));
            cmd.Parameters["@out"].Direction = ParameterDirection.Output;

            cmd.Parameters["@MaLoai"].Value = lkdDTO.MALOAIKD;
            //cmd.Parameters["@TenLoai"].Value = lkdDTO.TENLOAIKD;

            cmd.ExecuteNonQuery();
            int _kq = (int)cmd.Parameters["@out"].Value;
            _cn.Close();
            return _kq;
        }
    }
}
